﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Principal;
using System.Web.Security;

namespace Runda.EShop.Common.Utility
{
    public class CrmUserIdentity : IIdentity
    {
        private FormsAuthenticationTicket ticket;
        private UserTokenData userInfo;

        public CrmUserIdentity(FormsAuthenticationTicket ticket)
        {
            this.ticket = ticket;
            userInfo = new UserTokenData();
            userInfo.BuildUserData(ticket.UserData);
        }

        public UserTokenData LoginUser
        {
            get { return this.userInfo; }
        }

        #region IIdentity Members

        public string AuthenticationType
        {
            get { return "QFC.Sms"; }
        }

        public bool IsAuthenticated
        {
            get { return true; }
        }

        public string Name
        {
            get { return ticket.Name; }
        }

        #endregion
    }


    public class CrmUserPrincipal : IPrincipal
    {
        private CrmUserIdentity identity;  
        /// <summary>
        /// 使用身份信息构造实例
        /// </summary>
        /// <param name="identity">HR快线身份信息</param>
        public CrmUserPrincipal(CrmUserIdentity identity)
        {
            this.identity = identity;
       
        }
        /// <summary>
        /// 获取HR快线的登录用户的身份信息
        /// </summary>
        public CrmUserIdentity Identity
        {
            get { return identity; }
        }
        IIdentity IPrincipal.Identity
        {
            get { return identity; }
        } 

        public bool IsInRole(string role)
        {
            return false;
        }
         
    }

}